let selectionApp = new Vue({
    el: '#selectionApp',
    data: {
        loading: 1,
        selectedOption: '', // 初始值为空
        currentDate: '',
        load: true,
        tags: [],
        statusCreate: [], // 创建时间
        selection: [], // 视频列表主页
        next: [],  // 下一页
        checkbox: [],  // 是否显示
        isVisible: null,  // 是否显示删除内容
        isMessage: false, // 是否显示消息
        message: '',  // 消息内容 // 消息内容

    },
    methods: {
        selectionApp: function () {
            console.log("selectionApp")
            $.ajax({
                url: '/web/collectionIndexSelection/all',
                method: 'GET',
                success: function (e) {
                    console.log("selection{}", e);
                    selectionApp.selection = e;
                    selectionApp.load = false;
                    selectionApp.loading = 0;
                    for (let i = 0; i < selectionApp.selection.length; i++) {
                        if (selectionApp.selection[i].type === 1) {
                            selectionApp.selection[i].type = "电影页面";
                        }
                        if (selectionApp.selection[i].type === 2) {
                            selectionApp.selection[i].type = "剧集页面";
                        } else if (selectionApp.selection[i].type === 3) {
                            selectionApp.selection[i].type = "综艺页面";
                        } else if (selectionApp.selection[i].type === 4) {
                            selectionApp.selection[i].type = "动画页面";
                        } else if (selectionApp.selection[i].type === 5) {
                            selectionApp.selection[i].type = "推荐页面";
                        }
                    }

                }
            })
        },

        onUpdate: function (res) {
            console.log("update", res)
            $.ajax({
                url: '/web/collectionIndexSelection/update',
                method: 'GET',
                data: {
                    id: res.id,
                    content: res.content,
                    sortId: res.sortId,
                    scroll: res.scroll
                },
                success: function (res) {
                    console.log("res{}", res);
                    if (res.code == OK) {
                        selectionApp.onmessage("修改成功");
                        console.log("成功修改");
                    }
                },
                error: function (e) {
                    console.log("修改失败");
                    selectionApp.onmessage("修改失败");
                }
            })

        },
        // 获取视频类型
        onTags: function () {
            $.ajax({
                url: '/web/collectionTag/list',
                method: 'GET',
                success: function (res) {
                    console.log("res{}", res);
                    selectionApp.tags = res;
                },
                error: function (e) {
                    console.log("获取视频类型信息失败");
                }
            })

        },


        onmessage: function (message) {
            selectionApp.message = message;
            selectionApp.isMessage = true;
            setTimeout(function () {
                selectionApp.isMessage = false;
            }, 2000);
        },

        // 获取当前时间
        formatDate(date) {
            const year = date.getFullYear();
            const month = String(date.getMonth() + 1).padStart(2, '0');
            const day = String(date.getDate()).padStart(2, '0');
            const hours = String(date.getHours()).padStart(2, '0');
            const minutes = String(date.getMinutes()).padStart(2, '0');
            const seconds = String(date.getSeconds()).padStart(2, '0');
            return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
        },
        updateDate() {
            const now = new Date();
            this.currentDate = this.formatDate(now);
        }

    }, created: function () {
        // 初始化日期
        this.updateDate();
        // 每秒更新时间
        this.interval = setInterval(this.updateDate, 1000);
        this.selectionApp();
        this.onTags();
    },
    beforeDestroy() {
        // 清除定时器
        clearInterval(this.interval);
    }
})